package com.ruoyi.web.controller.laiqianba.sms;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.SmsTemplateInfo;
import com.ruoyi.laiqianba.service.ISmsTemplateInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 短信模板Controller
 * 
 * @author ruoyi
 * @date 2023-08-13
 */
@RestController
@RequestMapping("/sms/templateInfo")
public class SmsTemplateInfoController extends BaseController
{
    @Autowired
    private ISmsTemplateInfoService smsTemplateInfoService;

    /**
     * 查询短信模板列表
     */
    @PreAuthorize("@ss.hasPermi('sms:templateInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmsTemplateInfo smsTemplateInfo)
    {
        startPage();
        List<SmsTemplateInfo> list = smsTemplateInfoService.selectSmsTemplateInfoList(smsTemplateInfo);
        return getDataTable(list);
    }

    /**
     * 导出短信模板列表
     */
    @PreAuthorize("@ss.hasPermi('sms:templateInfo:export')")
    @Log(title = "短信模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmsTemplateInfo smsTemplateInfo)
    {
        List<SmsTemplateInfo> list = smsTemplateInfoService.selectSmsTemplateInfoList(smsTemplateInfo);
        ExcelUtil<SmsTemplateInfo> util = new ExcelUtil<SmsTemplateInfo>(SmsTemplateInfo.class);
        util.exportExcel(response, list, "短信模板数据");
    }

    /**
     * 获取短信模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('sms:templateInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(smsTemplateInfoService.selectSmsTemplateInfoById(id));
    }

    /**
     * 新增短信模板
     */
    @PreAuthorize("@ss.hasPermi('sms:templateInfo:add')")
    @Log(title = "短信模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmsTemplateInfo smsTemplateInfo)
    {
        return toAjax(smsTemplateInfoService.insertSmsTemplateInfo(smsTemplateInfo));
    }

    /**
     * 修改短信模板
     */
    @PreAuthorize("@ss.hasPermi('sms:templateInfo:edit')")
    @Log(title = "短信模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmsTemplateInfo smsTemplateInfo)
    {
        return toAjax(smsTemplateInfoService.updateSmsTemplateInfo(smsTemplateInfo));
    }

    /**
     * 删除短信模板
     */
    @PreAuthorize("@ss.hasPermi('sms:templateInfo:remove')")
    @Log(title = "短信模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smsTemplateInfoService.deleteSmsTemplateInfoByIds(ids));
    }
}
